<?php
header('Content-Type: application/json; charset=utf-8', true);
define('GOOGLE_LAT_LONG_URL', 'http://maps.google.com/maps/api/geocode/json?address=__ADDRESS__&sensor=false');

$json = array('error' => true, 'lat' => .0, 'lon' => .0);
if (isset($_GET['address'])) {
	$googleJson = @file_get_contents(str_replace('__ADDRESS__', urlencode($_GET['address']), GOOGLE_LAT_LONG_URL));
	
	if ($googleJson !== false && ($googleJson = json_decode($googleJson, true)) !== NULL
	    && strtolower($googleJson['status']) === 'ok') {
		$json['error'] = false;
		$json['lat'] = $googleJson['results'][0]['geometry']['location']['lat'];
		$json['lon'] = $googleJson['results'][0]['geometry']['location']['lng'];
	}
}

die(json_encode($json));
?>